package com.hm.common.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.data.domain.Page;

/**
 * @author shishun.wang
 * @date 2016年6月3日 上午1:49:37
 * @version 1.0
 * @describe 
 */
public class PageInfo<T> implements Serializable {
	
	private static final long serialVersionUID = 1L;

	private List<T> content = new ArrayList<T>(0);
	
	private int totalPage;
	
	private long totalSize;
	
	private int pageNumber;
	
	private int pageSize;
	
	public PageInfo(int pageNumber,int pageSize){
		this.pageNumber = (pageNumber >0 ? (pageNumber - 1):0);//页码从0开始
		this.pageSize = pageSize;
	}

	public List<T> getContent() {
		return content;
	}

	public void setContent(List<T> content) {
		this.content = content;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public long getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(long totalSize) {
		this.totalSize = totalSize;
	}

	public int getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public PageInfo<T> execute(Page<T> page,List<T> content){
		this.content = content;
		this.totalPage = page.getTotalPages();
		this.totalSize = page.getTotalElements();
		return this;
	}
}
